home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / include / renderers / directx9GUIRenderer / d3d9renderer.h next >
Encoding:
C/C++ Source or Header  |  2005-11-08  |  10.2 KB  |  346 lines

  1. /************************************************************************
  2.     filename:     d3d9renderer.h
  3.     created:    17/7/2004
  4.     author:        Paul D Turner with D3D 9 Updates by Magnus â•“sterlind
  5.     
  6.     purpose:    Interface for DirectX 9.0 Renderer class
  7. *************************************************************************/
  8. /*************************************************************************
  9.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. /*************************************************************************
  27.     This file contains code that is specific to Win32 and DirectX
  28. *************************************************************************/
  29. #ifndef _d3d9renderer_h_
  30. #define _d3d9renderer_h_
  31.  
  32. #include "CEGUIBase.h"
  33. #include "CEGUIRenderer.h"
  34. #include "CEGUITexture.h"
  35. #include <d3d9.h>
  36. #include <list>
  37. #include <set>
  38.  
  39. #ifdef DIRECTX9_GUIRENDERER_EXPORTS
  40. #define DIRECTX9_GUIRENDERER_API __declspec(dllexport)
  41. #else
  42. #define DIRECTX9_GUIRENDERER_API __declspec(dllimport)
  43. #endif
  44.  
  45.  
  46. #if defined(_MSC_VER)
  47. #    pragma warning(push)
  48. #    pragma warning(disable : 4251)
  49. #endif
  50.  
  51.  
  52. // Start of CEGUI namespace section
  53. namespace CEGUI
  54. {
  55. /*************************************************************************
  56.     Forward refs
  57. *************************************************************************/
  58. class DirectX9Texture;
  59.  
  60. /*!
  61. \brief
  62.     Renderer class to interface with Microsoft DirectX 9.0
  63. */
  64. class DIRECTX9_GUIRENDERER_API DirectX9Renderer : public Renderer
  65. {
  66. public:
  67.     /*!
  68.     \brief
  69.         Constructor for Direct3D 9.0 Renderer object
  70.  
  71.     \param device
  72.         Pointer to the IDirect3DDevice9 interface object that will be used for all rendering
  73.  
  74.     \param max_quads
  75.         Obsolete.  Set to 0.
  76.     */
  77.     DirectX9Renderer(LPDIRECT3DDEVICE9 device, uint max_quads);
  78.  
  79.     /*!
  80.     \brief
  81.         Destructor for DirectX9Renderer objects
  82.     */
  83.     virtual ~DirectX9Renderer(void);
  84.  
  85.     // add's a quad to the list to be rendered
  86.     virtual    void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
  87.  
  88.     // perform final rendering for all queued renderable quads.
  89.     virtual    void    doRender(void);
  90.  
  91.     // clear the queue
  92.     virtual    void    clearRenderList(void);
  93.  
  94.  
  95.     /*!
  96.     \brief
  97.         Enable or disable the queueing of quads from this point on.
  98.  
  99.         This only affects queueing.  If queueing is turned off, any calls to addQuad will cause the quad to be rendered directly.  Note that
  100.         disabling queueing will not cause currently queued quads to be rendered, nor is the queue cleared - at any time the queue can still
  101.         be drawn by calling doRender, and the list can be cleared by calling clearRenderList.  Re-enabling the queue causes subsequent quads
  102.         to be added as if queueing had never been disabled.
  103.  
  104.     \param setting
  105.         true to enable queueing, or false to disable queueing (see notes above).
  106.  
  107.     \return
  108.         Nothing
  109.     */
  110.     virtual void    setQueueingEnabled(bool setting)        {d_queueing = setting;}
  111.  
  112.  
  113.     // create an empty texture
  114.     virtual    Texture*    createTexture(void);
  115.  
  116.     // create a texture and load it with the specified file.
  117.     virtual    Texture*    createTexture(const String& filename, const String& resourceGroup);
  118.  
  119.     // create a texture and set it to the specified size
  120.     virtual    Texture*    createTexture(float size);
  121.  
  122.     // destroy the given texture
  123.     virtual    void        destroyTexture(Texture* texture);
  124.  
  125.     // destroy all textures still active
  126.     virtual void        destroyAllTextures(void);
  127.  
  128.     // return ptr to device
  129.     LPDIRECT3DDEVICE9    getDevice(void) const        {return d_device;}
  130.  
  131.  
  132.     /*!
  133.     \brief
  134.         Return whether queueing is enabled.
  135.  
  136.     \return
  137.         true if queueing is enabled, false if queueing is disabled.
  138.     */
  139.     virtual bool    isQueueingEnabled(void) const    {return d_queueing;}
  140.  
  141.  
  142.     /*!
  143.     \brief
  144.     Return the current width of the display in pixels
  145.  
  146.     \return
  147.     float value equal to the current width of the display in pixels.
  148.     */
  149.     virtual float    getWidth(void) const        {return d_display_area.getWidth();}
  150.  
  151.  
  152.     /*!
  153.     \brief
  154.     Return the current height of the display in pixels
  155.  
  156.     \return
  157.     float value equal to the current height of the display in pixels.
  158.     */
  159.     virtual float    getHeight(void) const        {return d_display_area.getHeight();}
  160.  
  161.  
  162.     /*!
  163.     \brief
  164.     Return the size of the display in pixels
  165.  
  166.     \return
  167.     Size object describing the dimensions of the current display.
  168.     */
  169.     virtual Size    getSize(void) const            {return d_display_area.getSize();}
  170.  
  171.  
  172.     /*!
  173.     \brief
  174.     Return a Rect describing the screen
  175.  
  176.     \return
  177.     A Rect object that describes the screen area.  Typically, the top-left values are always 0, and the size of the area described is
  178.     equal to the screen resolution.
  179.     */
  180.     virtual Rect    getRect(void) const            {return d_display_area;}
  181.  
  182.  
  183.     /*!
  184.     \brief
  185.         Return the maximum texture size available
  186.  
  187.     \return
  188.         Size of the maximum supported texture in pixels (textures are always assumed to be square)
  189.     */
  190.     virtual    uint    getMaxTextureSize(void) const        {return d_maxTextureSize;}
  191.  
  192.  
  193.     /*!
  194.     \brief
  195.         Return the horizontal display resolution dpi
  196.  
  197.     \return
  198.         horizontal resolution of the display in dpi.
  199.     */
  200.     virtual    uint    getHorzScreenDPI(void) const    {return 96;}
  201.  
  202.  
  203.     /*!
  204.     \brief
  205.         Return the vertical display resolution dpi
  206.  
  207.     \return
  208.         vertical resolution of the display in dpi.
  209.     */
  210.     virtual    uint    getVertScreenDPI(void) const    {return 96;}
  211.  
  212.  
  213.     /*!
  214.     \brief
  215.         Direct3D support method that must be called prior to a Reset call on the
  216.         Direct3DDevice; this is required so that the GUI renderer can release any
  217.         unmanaged D3D resources as needed for the device reset to succeed.
  218.     */
  219.     virtual    void    preD3DReset(void);
  220.  
  221.  
  222.     /*!
  223.     \brief
  224.         Direct3D support method that must be called after a Reset call on the
  225.         Direct3DDevice; this is required so that the GUI renderer can rebuild any
  226.         unmanaged D3D resources after the device has been reset.
  227.     */
  228.     virtual    void    postD3DReset(void);
  229.  
  230.  
  231.     /*!
  232.     \brief
  233.         Set the size of the display in pixels.
  234.  
  235.         You do not have to call this method under normal operation as the system
  236.         will automatically extract the size from the current view port.
  237.  
  238.     \note
  239.         This method will cause the EventDisplaySizeChanged event to fire if the
  240.         display size has changed.
  241.  
  242.     \param sz
  243.         Size object describing the size of the display.
  244.  
  245.     \return
  246.         Nothing.
  247.     */
  248.     void    setDisplaySize(const Size& sz);
  249.  
  250.  
  251. private:
  252.     /************************************************************************
  253.         Implementation Constants
  254.     ************************************************************************/
  255.     static const int            VERTEX_PER_QUAD;                            //!< number of vertices per quad
  256.     static const int            VERTEX_PER_TRIANGLE;                        //!< number of vertices for a triangle
  257.     static const int            VERTEXBUFFER_CAPACITY;                        //!< capacity of the allocated vertex buffer
  258.     static const ulong            VERTEX_FVF;                                    //!< FVF specifier constant
  259.  
  260.     /*************************************************************************
  261.         Implementation Structs & classes
  262.     *************************************************************************/
  263.     /*!
  264.     \brief
  265.         FVF structure used for all vertices.
  266.     */
  267.     struct QuadVertex {
  268.         FLOAT x, y, z, rhw;        //!< The transformed position for the vertex.
  269.         DWORD diffuse;            //!< colour of the vertex
  270.         float tu1, tv1;            //!< texture coordinates
  271.     };
  272.  
  273.     /*!
  274.     \brief
  275.         structure holding details about a quad to be drawn
  276.     */
  277.     struct QuadInfo
  278.     {
  279.         LPDIRECT3DTEXTURE9    texture;
  280.         Rect                position;
  281.         float                z;
  282.         Rect                texPosition;
  283.         ulong                topLeftCol;
  284.         ulong                topRightCol;
  285.         ulong                bottomLeftCol;
  286.         ulong                bottomRightCol;
  287.  
  288.         QuadSplitMode       splitMode;
  289.  
  290.         bool operator<(const QuadInfo& other) const
  291.         {
  292.             // this is intentionally reversed.
  293.             return z > other.z;
  294.         }
  295.     };
  296.  
  297.  
  298.     /*************************************************************************
  299.         Implementation Methods
  300.     *************************************************************************/
  301.     // setup states etc
  302.     void    initPerFrameStates(void);
  303.  
  304.     // renders whatever is in the vertex buffer
  305.     void    renderVBuffer(void);
  306.  
  307.     // sort quads list according to texture
  308.     void    sortQuads(void);
  309.  
  310.     // render a quad directly to the display
  311.     void    renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
  312.  
  313.     // return size of device view port (if possible)
  314.     Size    getViewportSize(void);
  315.  
  316.     // method to do work of constructor
  317.     void    constructor_impl(LPDIRECT3DDEVICE9 device, const Size& display_size);
  318.  
  319.  
  320.     /*************************************************************************
  321.         Implementation Data
  322.     *************************************************************************/
  323.     Rect                d_display_area;
  324.  
  325.     typedef std::multiset<QuadInfo>        QuadList;
  326.     QuadList d_quadlist;
  327.     bool    d_queueing;        //!< setting for queueing control.
  328.  
  329.     LPDIRECT3DDEVICE9        d_device;            //!< Base Direct3DDevice9 interface that we use for rendering
  330.     LPDIRECT3DTEXTURE9        d_currTexture;        //!< currently set texture;
  331.     LPDIRECT3DVERTEXBUFFER9    d_buffer;            //!< vertex buffer to queue sprite rendering
  332.     int                        d_bufferPos;        //!< index into buffer where next vertex should be put.
  333.  
  334.     std::list<DirectX9Texture*>    d_texturelist;        //!< List used to track textures.
  335.  
  336.     uint    d_maxTextureSize;        //!< Holds maximum supported texture size (in pixels).
  337. };
  338.  
  339. } // End of  CEGUI namespace section
  340.  
  341. #if defined(_MSC_VER)
  342. #    pragma warning(pop)
  343. #endif
  344.  
  345. #endif    // end of guard _d3d9renderer_h_
  346.